ABAP Select data from SAP table /PICM/S_BAPIMEPOACCOUNTX into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP /PICM/S_BAPIMEPOACCOUNTX table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to /PICM/S_BAPIMEPOACCOUNTX. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the /PICM/S_BAPIMEPOACCOUNTX table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_/PICM/S_BAPIMEPOACCOUNTX TYPE STANDARD TABLE OF /PICM/S_BAPIMEPOACCOUNTX,
      WA_/PICM/S_BAPIMEPOACCOUNTX TYPE /PICM/S_BAPIMEPOACCOUNTX,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: </PICM/S_BAPIMEPOACCOUNTX> TYPE /PICM/S_BAPIMEPOACCOUNTX.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/PICM/S_BAPIMEPOACCOUNTX.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /PICM/S_BAPIMEPOACCOUNTX
  INTO TABLE IT_/PICM/S_BAPIMEPOACCOUNTX.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /PICM/S_BAPIMEPOACCOUNTX
*  INTO TABLE @DATA(IT_/PICM/S_BAPIMEPOACCOUNTX2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_/PICM/S_BAPIMEPOACCOUNTX INDEX 1 INTO DATA(WA_/PICM/S_BAPIMEPOACCOUNTX2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PICM/S_BAPIMEPOACCOUNTX ASSIGNING </PICM/S_BAPIMEPOACCOUNTX>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PICM/S_BAPIMEPOACCOUNTX>-PO_ITEM = 1.
</PICM/S_BAPIMEPOACCOUNTX>-SERIAL_NO = 1.
</PICM/S_BAPIMEPOACCOUNTX>-PO_ITEMX = 1.
</PICM/S_BAPIMEPOACCOUNTX>-SERIAL_NOX = 1.
</PICM/S_BAPIMEPOACCOUNTX>-DELETE_IND = 1.
ENDLOOP.

LOOP AT IT_/PICM/S_BAPIMEPOACCOUNTX INTO WA_/PICM/S_BAPIMEPOACCOUNTX.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PICM/S_BAPIMEPOACCOUNTX-CREAT_DATE, sy-vline,
WA_/PICM/S_BAPIMEPOACCOUNTX-QUANTITY, sy-vline,
WA_/PICM/S_BAPIMEPOACCOUNTX-DISTR_PERC, sy-vline,
WA_/PICM/S_BAPIMEPOACCOUNTX-NET_VALUE, sy-vline,
WA_/PICM/S_BAPIMEPOACCOUNTX-GL_ACCOUNT, sy-vline,
WA_/PICM/S_BAPIMEPOACCOUNTX-BUS_AREA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PICM/S_BAPIMEPOACCOUNTX you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_/PICM/S_BAPIMEPOACCOUNTX TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_/PICM/S_BAPIMEPOACCOUNTX INTO WA_/PICM/S_BAPIMEPOACCOUNTX. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/PICM/S_BAPIMEPOACCOUNTX_STR,
PO_ITEM TYPE STRING,
SERIAL_NO TYPE STRING,
PO_ITEMX TYPE STRING,
SERIAL_NOX TYPE STRING,
DELETE_IND TYPE STRING,
CREAT_DATE TYPE STRING,
QUANTITY TYPE STRING,
DISTR_PERC TYPE STRING,
NET_VALUE TYPE STRING,
GL_ACCOUNT TYPE STRING,
BUS_AREA TYPE STRING,
COSTCENTER TYPE STRING,
SD_DOC TYPE STRING,
ITM_NUMBER TYPE STRING,
SCHED_LINE TYPE STRING,
ASSET_NO TYPE STRING,
SUB_NUMBER TYPE STRING,
ORDERID TYPE STRING,
GR_RCPT TYPE STRING,
UNLOAD_PT TYPE STRING,
CO_AREA TYPE STRING,
COSTOBJECT TYPE STRING,
PROFIT_CTR TYPE STRING,
WBS_ELEMENT TYPE STRING,
NETWORK TYPE STRING,
RL_EST_KEY TYPE STRING,
PART_ACCT TYPE STRING,
CMMT_ITEM TYPE STRING,
REC_IND TYPE STRING,
FUNDS_CTR TYPE STRING,
FUND TYPE STRING,
FUNC_AREA TYPE STRING,
REF_DATE TYPE STRING,
TAX_CODE TYPE STRING,
TAXJURCODE TYPE STRING,
NOND_ITAX TYPE STRING,
ACTTYPE TYPE STRING,
CO_BUSPROC TYPE STRING,
RES_DOC TYPE STRING,
RES_ITEM TYPE STRING,
ACTIVITY TYPE STRING,
GRANT_NBR TYPE STRING,
BUDGET_PERIOD TYPE STRING,
FINAL_IND TYPE STRING,
FINAL_REASON TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PICM/S_BAPIMEPOACCOUNTX_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-PO_ITEM sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-SERIAL_NO sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-PO_ITEMX sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-SERIAL_NOX sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-DELETE_IND sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-CREAT_DATE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-QUANTITY sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-DISTR_PERC sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-NET_VALUE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-GL_ACCOUNT sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-BUS_AREA sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-COSTCENTER sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-SD_DOC sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-ITM_NUMBER sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-SCHED_LINE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-ASSET_NO sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-SUB_NUMBER sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-ORDERID sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-GR_RCPT sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-UNLOAD_PT sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-CO_AREA sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-COSTOBJECT sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-PROFIT_CTR sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-WBS_ELEMENT sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-NETWORK sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-RL_EST_KEY sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-PART_ACCT sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-CMMT_ITEM sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-REC_IND sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-FUNDS_CTR sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-FUND sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-FUNC_AREA sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-REF_DATE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-TAX_CODE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-TAXJURCODE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-NOND_ITAX sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-ACTTYPE sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-CO_BUSPROC sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-RES_DOC sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-RES_ITEM sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-ACTIVITY sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-GRANT_NBR sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-BUDGET_PERIOD sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-FINAL_IND sy-vline
WA_/PICM/S_BAPIMEPOACCOUNTX_STR-FINAL_REASON sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.