Thursday, January 20, 2022

Upload a picture into SAP and save it as standard text

REPORT ZPICUPLOAD LINE-SIZE 250.

*
INCLUDE OLE2INCL"OLE INCLUDE
************************************************************************
*
PARAMETERS:
   PICFILE(128TYPE DEFAULT 'C:\temp\xyz.jpg'"PCFILE TO UPLOAD
   TEXTNAME(128TYPE DEFAULT 'GOMERA'.         "NAME OF STANDARD TEXT
*
************************************************************************
DATATEXTTAB LIKE TLINE OCCURS 2000 WITH HEADER LINE.
DATABEGIN OF HEXTAB OCCURS 1000,
      LINE(33TYPE X,
      END OF HEXTAB.
DATASIZE TYPE .                    "SIZE OF FILE'
DATATEXTHEAD LIKE THEAD.
DATANAVIAGTOR TYPE OLE2_OBJECT.
************************************************************************
START-OF-SELECTION.
*
  PERFORM UPLOAD_PIC USING PICFILE TEXTNAME.
  PERFORM DOWNLOAD_PIC USING 'D:\TEMP\SAPTEST.JPG' TEXTNAME.
  PERFORM SHOW_PIC USING 'D:\TEMP\SAPTEST.JPG'.
*
END-OF-SELECTION.
*
************************************************************************
*                  upload picture (.jpg)
************************************************************************
FORM UPLOAD_PIC USING OSFILE SAPFILE.
 TEXTHEAD-TDNAME SAPFILE.
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            CODEPAGE '8400'
            FILETYPE 'BIN'
            FILENAME OSFILE
       IMPORTING
            FILELENGTH SIZE
       TABLES
            DATA_TAB HEXTAB
       EXCEPTIONS
            OTHERS   7.
  CALL FUNCTION 'INIT_TEXT'
       EXPORTING
            ID       'ST'
            LANGUAGE 'E'
            NAME     TEXTHEAD-TDNAME
            OBJECT   'TEXT'
       IMPORTING
            HEADER   TEXTHEAD
       TABLES
            LINES    TEXTTAB
       EXCEPTIONS
            OTHERS   5.
  CALL FUNCTION 'SAVE_TEXT'
       EXPORTING
            CLIENT          SY-MANDT
            HEADER          TEXTHEAD
            SAVEMODE_DIRECT 'X'
       TABLES
            LINES           TEXTTAB
       EXCEPTIONS
            OTHERS          5.
ENDFORM.                               "END OF UPLOADING
************************************************************************
*       FORM DOWNLOAD_PIC                                             *
************************************************************************
FORM DOWNLOAD_PIC USING OSFILE SAPFILE.
  LOOP AT TEXTTAB.
    HEXTAB-LINE TEXTTAB-TDLINE.
    APPEND HEXTAB.
  ENDLOOP.
  CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            BIN_FILESIZE SIZE
            CODEPAGE     '8400'
            FILENAME     OSFILE
            FILETYPE     'BIN'
       TABLES
            DATA_TAB     HEXTAB
       EXCEPTIONS
            OTHERS       7.
ENDFORM.                               " ENDOF DOWNLOAD PICTURE
************************************************************************
*       FORM SHOW_PIC                                                 *
************************************************************************
FORM SHOW_PIC USING OSFILE.
  DATA PATH(128TYPE C.
  CREATE OBJECT NAVIAGTOR 'INTERNETEXPLORER.APPLICATION'.
  SET PROPERTY OF NAVIAGTOR 'MENUBAR' 0.
  SET PROPERTY OF NAVIAGTOR 'TOOLBAR' 0.
  SET PROPERTY OF NAVIAGTOR 'STATUSBAR' 1.
  CONCATENATE 'FILE://' OSFILE INTO PATH.
  CALL METHOD OF NAVIAGTOR 'NAVIGATE' EXPORTING #1 PATH.
  SET PROPERTY OF NAVIAGTOR 'STATUSTEXT' 'PICTURE FROM SAP'.
  SET PROPERTY  OF NAVIAGTOR 'VISIBLE' 1.
ENDFORM.                               " ENDOF SHOW_PIC.

Wednesday, January 12, 2022

SAP ABAP: Smartforms/SAPscript formatting

 Smartforms Formatting

Following are the few useful formatting options:
Offset:
N left-most characters of the symbol value will not be displayed.
If symbol has the value 123456789, the following will be displayed:
&symbol& -> 123456789
&symbol+3& -> 456789
&symbol+7& -> 89
&symbol+12& ->
&symbol+0& -> 123456789


 Output Length
To define how many character positions should be copied from the value.
If symbol has the value 123456789.
&symbol(3)& -> 123
&symbol(7)& -> 1234567

 The SYST-UNAME field contains the logon name of a user called Einstein. The
Dictionary entry for this field contains an output length of 12.
&SYST-UNAME&… -> Einstein…
&SYST-UNAME(9)&… -> Einstein …
&SYST-UNAME(*)&… -> Einstein …

Omitting the Leading Sign
The S option can be used to ensure that the value is formatted without the sign.
The ITCDP-TDULPOS field contains the value -100.00. The ABAP/4 Dictionary
definition for this field includes a leading sign.
&ITCDP-TDULPOS& -> 100.00-
&ITCDP-TDULPOS(S)& -> 100.00

Leading Sign to the Left
This option enables you to specify that the leading sign should be placed to the left of the number.
&ITCDP-TDULPOS& -> 100.00-
&ITCDP-TDULPOS(<)& -> -100.00

Leading Sign to the Right
If you used the SET SIGN LEFT control command to specify that the leading sign should be output before the value, this specification can be overridden for individual symbols to enable these to be output with the leading sign to the right.
Syntax:
&symbol(>)&

Omitting Leading Zeros
Certain symbol values are output with leading zeros. If you wish to suppress these, you may do so with the Z option.
Assuming the current date is 1.1.1994, &DAY& -> 01
&DAY(Z)& -> 1

Space Compression
The C option has the effect of replacing each string of space characters with a single space and shifting the ’words’ to the left as necessary to close up the gaps.
Assuming ‘ Albert Einstein ‘ is the symbol value,
&symbol& -> Albert Einstein
&symbol(C)& -> Albert Einstein

Number of Decimal Places
A program symbol of one of the data types DEC, QUAN and FLTP can contain decimal place data. This option is used to override the Dictionary definition for the number of decimal places for the formatting of this symbol value.
The EKPO-MENGE field contains the value 1234.56. The Dictionary definition specifies 3 decimal places and an output length of 17.
&EKPO-MENGE& -> 1,234.560
&EKPO-MENGE(.1) -> 1,234.6
&EKPO-MENGE&(.4) -> 1,234.5600
&EKPO-MENGE&(.0) -> 1,235

Specifying an Exponent for Floating Point Numbers
The way that a floating point number is formatted depends on whether an exponent is specified.
PLMK-SOLLWERT field is assumed to have the value
123456.78 and to be of data type FLTP.
&PLMK-SOLLWERT& -> +1.23456780000000E+05
&PLMK-SOLLWERT(E3)& -> +123.456780000000E+03
&PLMK-SOLLWERT(E6)& -> +0.12345678000000E+06
&PLMK-SOLLWERT(E0)& -> +123456.780000000
&PLMK-SOLLWERT(E)& -> +123456.780000000

Right-Justified Output
Right-justified formatting can be specified with the R option. This option has to be used in conjunction with an output length specification. If symbol has the value 1234.
&symbol& -> 1234
&symbol(8R) -> 1234

Fill Characters
Leading spaces in a value can be replaced with a fill character.
The figure for customer sales in the KNA1-UMSAT field is $700. The Dictionary description of the field specifies an output length 8.
&KNA1-UMSAT& -> 700.00
&KNA1-UMSAT(F*)& -> **700.00
&KNA1-UMSAT(F0)& -> 00700.00

Suppress Output of Initial Value
The I option can be used to suppress the output of symbols which still contain their initial value.
Assuming KNA1-UMSAT contains the value 0 and the currency is DEM.
&KNA1-UMSAT& -> 0,00
&KNA1-UMSAT(I)& ->
If the field contains an amount other than 0, this value will be output in the normal way.
&KNA1-UMSAT& -> 700,00
&KNA1-UMSAT(I)& -> 700,00

Ignore Conversion Routines
SAPscript conversion routines specified in the Dictionary are automatically recognized and used when program symbols are being formatted. Using the K option can prevent these conversions.

Date Mask
The formatting for date fields can be defined with the SAPscript SET DATE MASK command. Executing this command causes all subsequent date fields to be output using the specified formatting.
/: SET DATE MASK = ‘date_mask’
The following templates may be used in the date mask:
DD day (two digits)
DDD name of day (abbreviated)
DDDD name of day (written out in full)
MM month (two digits)
MMM name of month (abbreviated)
MMMM name of month (written out in full)
YY year (two digits)
YYYY year (four digits)
LD day (formatted as for the L option)
LM month (formatted as for the L option)
LY year (formatted as for the L option)

Time Mask
You can use the SAPscript SET TIME MASK command to format time fields in a way that differs from the standard setting.
Assuming the current time is 10:08:12.
&TIME& -> 10:08:12
/: SET TIME MASK = ‘HH:MM’
&TIME& -> 10:08
/: SET TIME MASK = ‘HH hours MM minutes’
&TIME& -> 10 hours 08 minutes
&TIME(Z)& -> 10 hours 8 minutes

 Other Standard Outputs:
&DAY&, &MONTH&, &YEAR&, &HOURS&, &MINUTES&, &SECONDS&, &DATE&,
&TIME&, &PAGE&, &NEXTPAGE&.

Drop Down lists in the selection parameters

PROGRAM ztest.   TYPE-POOLS : vrm.   DATA : name TYPE vrm_id,        list TYPE vrm_values,        value LIKE LINE OF list. ...