Monday, May 22, 2017

XML file transformation with checking tags-

  

Xml file structure:

  <InvoiceAddress>    
                <Name>Salauddin Fashion House</Name>
                <PostalCode>1219</PostalCode>
                <City>Dhaka</City>
                <CountryCode>BD</CountryCode>

    </InvoiceAddress>


XML file Transformation code: 


 " if invoice tag not available 

<tt:cond s-check="not-initial(ref('INVOICEADD'))"

      " if name tag not available.

           <tt:cond s-check="not-initial(ref('INVOICEADD.NAME'))"
              <Name tt:value-ref="INVOICEADD.NAME"/>
            </tt:cond>
            
            " if name tag available.

            <tt:cond s-check="initial(ref('INVOICEADD.NAME'))">  
              <Name tt:value-ref="INVOICEADD.NAME"/>
            </tt:cond>

            <tt:cond s-check="not-initial(ref('INVOICEADD.POSTALCODE'))">
              <PostalCode tt:value-ref="INVOICEADD.POSTALCODE"/>
            </tt:cond>
            <tt:cond s-check="initial(ref('INVOICEADD.POSTALCODE'))">
              <PostalCode tt:value-ref="INVOICEADD.POSTALCODE"/>
            </tt:cond>

            <tt:cond s-check="not-initial(ref('INVOICEADD.CITY'))">
              <City tt:value-ref="INVOICEADD.CITY"/>
            </tt:cond>
            <tt:cond s-check="initial(ref('INVOICEADD.CITY'))">
              <City tt:value-ref="INVOICEADD.CITY"/>
            </tt:cond>

            <tt:cond s-check="not-initial(ref('INVOICEADD.COUNTRYCODE'))">
              <CountryCode tt:value-ref="INVOICEADD.COUNTRYCODE"/>
            </tt:cond>
            <tt:cond s-check="initial(ref('INVOICEADD.COUNTRYCODE'))">
              <CountryCode tt:value-ref="INVOICEADD.COUNTRYCODE"/>
            </tt:cond>

          </tt:cond>




          " if invoice tag available 

          <tt:cond s-check="initial(ref('INVOICEADD'))">   

            <InvoiceAddress>


              <tt:cond s-check="not-initial(ref('INVOICEADD.NAME'))">
                <Name tt:value-ref="INVOICEADD.NAME"/>
              </tt:cond>
              <tt:cond s-check="initial(ref('INVOICEADD.NAME'))">
                <Name tt:value-ref="INVOICEADD.NAME"/>
              </tt:cond>

              <tt:cond s-check="not-initial(ref('INVOICEADD.POSTALCODE'))">
                <PostalCode tt:value-ref="INVOICEADD.POSTALCODE"/>
              </tt:cond>
              <tt:cond s-check="initial(ref('INVOICEADD.POSTALCODE'))">
                <PostalCode tt:value-ref="INVOICEADD.POSTALCODE"/>
              </tt:cond>


              <tt:cond s-check="not-initial(ref('INVOICEADD.CITY'))">
                <City tt:value-ref="INVOICEADD.CITY"/>
              </tt:cond>
              <tt:cond s-check="initial(ref('INVOICEADD.CITY'))">
                <City tt:value-ref="INVOICEADD.CITY"/>
              </tt:cond>

              <tt:cond s-check="not-initial(ref('INVOICEADD.COUNTRYCODE'))">
                <CountryCode tt:value-ref="INVOICEADD.COUNTRYCODE"/>
              </tt:cond>
              <tt:cond s-check="initial(ref('INVOICEADD.COUNTRYCODE'))">
                <CountryCode tt:value-ref="INVOICEADD.COUNTRYCODE"/>
              </tt:cond>

            </InvoiceAddress>
          </tt:cond>



Thursday, March 23, 2017

Messages in ABAP


Messages are usually used to tell the user what is going on. The following types of messages are available in ABAP.

A Termination The message appears in a dialog box, and the program terminates. When the user has confirmed the message, control returns to the next-highest area menu.

E Error Depending on the program context, an error dialog appears or the program terminates.

I Status The message appears in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement.

S Error The program continues normally after the MESSAGE statement, and the message is displayed in the status bar of the next screen.

W Warning Depending on the program context, an error dialog appears or the program terminates.

X Exit No message is displayed, and the program terminates with a short dump. Program terminations with a short dump normally only occur when a runtime error occurs.

The syntax for issuing a message is as follows.
MESSAGE <message> TYPE <message type>.
We can issue a status message as follows. Status message will be displayed in the status bar. After the message is displayed the program continues after the MESSAGE statement.
MESSAGE 'This is a status message' TYPE 'S'.

Information message will be displayed in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement.
MESSAGE 'This is an information message' TYPE 'I'.

Error message in report programs will be displayed in the status bar and when the user press enter, the program terminates.
MESSAGE 'This is an error message' TYPE 'E'.

Warning message behaves similar to error message in report programs.
Exit Message – No message is displayed, and the program terminates with a short dump. Short

dumps can be viewed in t-code ST22.
MESSAGE 'This produces short dump' TYPE 'X'.

Termination Message appears in a dialog box, and the program terminates. When the user has confirmed the message, control returns to the next-highest area menu.
MESSAGE 'This is termination message' TYPE 'A'.

Instead of hardcode the message text in the program we can maintain the message text in text symbols. In order to maintain text symbols use the menu path Goto->Text Elements->Text Symbols in ABAP editor.

In the text symbols screen we can maintain the messages with a 3 character identifier.

Then use the following message statement.
MESSAGE text-001 TYPE 'I'.


Upload material basic data text using excel file

" this program is used for uploading material basic data text using xl file.
"xl file will be consists of two columns, Material number & text field without header.

REPORT zupload_basic_data.

TYPE-POOLS: truxs.
*----DATA DECLARATION

TYPES: BEGIN OF ty_excel,
         matnr TYPE ekpo-matnr,
         text  TYPE string,
       END OF ty_excel.
DATA: it_raw TYPE truxs_t_text_data.
DATA: t_excel TYPE STANDARD TABLE OF ty_excel,
      w_excel TYPE ty_excel.

DATA: BEGIN OF t_desc OCCURS 0,
        header(50) TYPE c,
      END OF t_desc,
      filename TYPE string,
      soldp    TYPE name2,
      shipp    TYPE name2.


SELECTION-SCREEN BEGIN OF BLOCK database-selection
  WITH FRAME TITLE text-001.
PARAMETERS p_file TYPE rlgrap-filename MODIF ID s1.
SELECTION-SCREEN END OF BLOCK database-selection.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.

START-OF-SELECTION.

" reading the xl file with material & basic text

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = it_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = t_excel[]
    EXCEPTIONS
      convertion_failed    = 1
      OTHERS               = 0.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


  DATA: i_line LIKE TABLE OF tline WITH HEADER LINE,
        head   LIKE thead.

  LOOP AT t_excel INTO w_excel.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_excel-matnr
      IMPORTING
        output = w_excel-matnr.

    head-tdobject = 'MATERIAL'.

    head-tdname = w_excel-matnr. "Material number

    head-tdid = 'GRUN'.

    head-tdspras = 'EN'.

    i_line-tdline = w_excel-text.

    APPEND i_line.

    CALL FUNCTION 'SAVE_TEXT'
      EXPORTING
        header          = head
        savemode_direct = 'X'
      TABLES
        lines           = i_line
      EXCEPTIONS
        id              = 1
        language        = 2
        name            = 3
        object          = 4
        OTHERS          = 5.

    IF sy-subrc <> 0.

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.
    REFRESH: i_line.
  ENDLOOP.

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. ...