ABAP Select data from SAP table BAPI1300ADDDAX 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 BAPI1300ADDDAX 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 BAPI1300ADDDAX. 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 BAPI1300ADDDAX 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_BAPI1300ADDDAX TYPE STANDARD TABLE OF BAPI1300ADDDAX,
      WA_BAPI1300ADDDAX TYPE BAPI1300ADDDAX,
      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: <BAPI1300ADDDAX> TYPE BAPI1300ADDDAX.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM BAPI1300ADDDAX
  INTO TABLE IT_BAPI1300ADDDAX.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM BAPI1300ADDDAX
*  INTO TABLE @DATA(IT_BAPI1300ADDDAX2).
*--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_BAPI1300ADDDAX INDEX 1 INTO DATA(WA_BAPI1300ADDDAX2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_BAPI1300ADDDAX ASSIGNING <BAPI1300ADDDAX>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<BAPI1300ADDDAX>-CLIENT = 1.
<BAPI1300ADDDAX>-INSTITUTION = 1.
<BAPI1300ADDDAX>-SRVCATID = 1.
<BAPI1300ADDDAX>-SERVICEID = 1.
<BAPI1300ADDDAX>-TO_DATE = 1.
ENDLOOP.

LOOP AT IT_BAPI1300ADDDAX INTO WA_BAPI1300ADDDAX.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_BAPI1300ADDDAX-FROM_DATE, sy-vline,
WA_BAPI1300ADDDAX-FROM_DATEX, sy-vline,
WA_BAPI1300ADDDAX-MLS_MAINDEPT, sy-vline,
WA_BAPI1300ADDDAX-MLS_MAINDEPTX, sy-vline,
WA_BAPI1300ADDDAX-MLS_EXTPHYS, sy-vline,
WA_BAPI1300ADDDAX-MLS_EXTPHYSX, sy-vline.
ENDLOOP. *Add any further fields from structure WA_BAPI1300ADDDAX 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_BAPI1300ADDDAX 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_BAPI1300ADDDAX INTO WA_BAPI1300ADDDAX. *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.

*Conversion exit ALPHA, internal->external for field INSTITUTION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1300ADDDAX-INSTITUTION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1300ADDDAX-INSTITUTION.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SRVCATID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1300ADDDAX-SRVCATID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1300ADDDAX-SRVCATID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SERVICEID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1300ADDDAX-SERVICEID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1300ADDDAX-SERVICEID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ASSIGN_FRATE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_BAPI1300ADDDAX-ASSIGN_FRATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_BAPI1300ADDDAX-ASSIGN_FRATE.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_BAPI1300ADDDAX_STR,
CLIENT TYPE STRING,
INSTITUTION TYPE STRING,
SRVCATID TYPE STRING,
SERVICEID TYPE STRING,
TO_DATE TYPE STRING,
FROM_DATE TYPE STRING,
FROM_DATEX TYPE STRING,
MLS_MAINDEPT TYPE STRING,
MLS_MAINDEPTX TYPE STRING,
MLS_EXTPHYS TYPE STRING,
MLS_EXTPHYSX TYPE STRING,
MLS_MAINDEPTI TYPE STRING,
MLS_MAINDEPTIX TYPE STRING,
MLS_EXTPHYSI TYPE STRING,
MLS_EXTPHYSIX TYPE STRING,
SLS_MAINDEPT TYPE STRING,
SLS_MAINDEPTX TYPE STRING,
SLS_EXTPHYS TYPE STRING,
SLS_EXTPHYSX TYPE STRING,
PLAN_AMOUNT TYPE STRING,
PLAN_AMOUNTX TYPE STRING,
UPDATE_DATE TYPE STRING,
UPDATE_DATEX TYPE STRING,
UPDATE_USER TYPE STRING,
UPDATE_USERX TYPE STRING,
SLS_MAINDEPTI TYPE STRING,
SLS_MAINDEPTIX TYPE STRING,
SLS_EXTPHYSI TYPE STRING,
SLS_EXTPHYSIX TYPE STRING,
CF_PERMAIN TYPE STRING,
CF_PERMAINX TYPE STRING,
CF_MATMAIN TYPE STRING,
CF_MATMAINX TYPE STRING,
CF_PERMAINBAS TYPE STRING,
CF_PERMAINBASX TYPE STRING,
CF_MATMAINBAS TYPE STRING,
CF_MATMAINBASX TYPE STRING,
MIN_LS TYPE STRING,
MIN_LSX TYPE STRING,
ASSIGN_FRATE TYPE STRING,
ASSIGN_FRATEX TYPE STRING,
MODULE_NO TYPE STRING,
MODULE_NOX TYPE STRING,
CF_PEREXT TYPE STRING,
CF_PEREXTX TYPE STRING,
CF_MATEXT TYPE STRING,
CF_MATEXTX TYPE STRING,
CF_PEREXTA TYPE STRING,
CF_PEREXTAX TYPE STRING,
CF_MATEXTA TYPE STRING,
CF_MATEXTAX TYPE STRING,
CF_PEREXTB TYPE STRING,
CF_PEREXTBX TYPE STRING,
CF_MATEXTB TYPE STRING,
CF_MATEXTBX TYPE STRING,
CF_PEREXTC TYPE STRING,
CF_PEREXTCX TYPE STRING,
CF_MATEXTC TYPE STRING,
CF_MATEXTCX TYPE STRING,
CF_PEREXTBAS TYPE STRING,
CF_PEREXTBASX TYPE STRING,
CF_MATEXTBAS TYPE STRING,
CF_MATEXTBASX TYPE STRING,
MLS_MAINDPT TYPE STRING,
MLS_MAINDPTX TYPE STRING,
ULS_MAINDPT TYPE STRING,
ULS_MAINDPTX TYPE STRING,
RULS_MAINDPT TYPE STRING,
RULS_MAINDPTX TYPE STRING,
MLS_EXTDPT TYPE STRING,
MLS_EXTDPTX TYPE STRING,
ULS_EXTDPT TYPE STRING,
ULS_EXTDPTX TYPE STRING,
RULS_EXTDPT TYPE STRING,
RULS_EXTDPTX TYPE STRING,
LLS_MAINDPT TYPE STRING,
LLS_MAINDPTX TYPE STRING,
RLLS_MAINDPT TYPE STRING,
RLLS_MAINDPTX TYPE STRING,
LLS_EXTDPT TYPE STRING,
LLS_EXTDPTX TYPE STRING,
RLLS_EXTDPT TYPE STRING,
RLLS_EXTDPTX TYPE STRING,
RETR_MAINDPT TYPE STRING,
RETR_MAINDPTX TYPE STRING,
RETR_EXTDPT TYPE STRING,
RETR_EXTDPTX TYPE STRING,
TDRG_MAINDPT TYPE STRING,
TDRG_MAINDPTX TYPE STRING,
TDRG_EXTDPT TYPE STRING,
TDRG_EXTDPTX TYPE STRING,
MINLS_MAINDPT TYPE STRING,
MINLS_MAINDPTX TYPE STRING,
MINLS_EXTDPT TYPE STRING,
MINLS_EXTDPTX TYPE STRING,
NORET_MAINDPT TYPE STRING,
NORET_MAINDPTX TYPE STRING,
NORET_EXTDPT TYPE STRING,
NORET_EXTDPTX TYPE STRING,
CATEGORY TYPE STRING,
CATEGORYX TYPE STRING,
CATEGORY_L TYPE STRING,
CATEGORY_LX TYPE STRING,
CATEGORY_R TYPE STRING,
CATEGORY_RX TYPE STRING,
CATEGORY_B TYPE STRING,
CATEGORY_BX TYPE STRING,END OF T_EKKO_STR. DATA: WA_BAPI1300ADDDAX_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_BAPI1300ADDDAX_STR-CLIENT sy-vline
WA_BAPI1300ADDDAX_STR-INSTITUTION sy-vline
WA_BAPI1300ADDDAX_STR-SRVCATID sy-vline
WA_BAPI1300ADDDAX_STR-SERVICEID sy-vline
WA_BAPI1300ADDDAX_STR-TO_DATE sy-vline
WA_BAPI1300ADDDAX_STR-FROM_DATE sy-vline
WA_BAPI1300ADDDAX_STR-FROM_DATEX sy-vline
WA_BAPI1300ADDDAX_STR-MLS_MAINDEPT sy-vline
WA_BAPI1300ADDDAX_STR-MLS_MAINDEPTX sy-vline
WA_BAPI1300ADDDAX_STR-MLS_EXTPHYS sy-vline
WA_BAPI1300ADDDAX_STR-MLS_EXTPHYSX sy-vline
WA_BAPI1300ADDDAX_STR-MLS_MAINDEPTI sy-vline
WA_BAPI1300ADDDAX_STR-MLS_MAINDEPTIX sy-vline
WA_BAPI1300ADDDAX_STR-MLS_EXTPHYSI sy-vline
WA_BAPI1300ADDDAX_STR-MLS_EXTPHYSIX sy-vline
WA_BAPI1300ADDDAX_STR-SLS_MAINDEPT sy-vline
WA_BAPI1300ADDDAX_STR-SLS_MAINDEPTX sy-vline
WA_BAPI1300ADDDAX_STR-SLS_EXTPHYS sy-vline
WA_BAPI1300ADDDAX_STR-SLS_EXTPHYSX sy-vline
WA_BAPI1300ADDDAX_STR-PLAN_AMOUNT sy-vline
WA_BAPI1300ADDDAX_STR-PLAN_AMOUNTX sy-vline
WA_BAPI1300ADDDAX_STR-UPDATE_DATE sy-vline
WA_BAPI1300ADDDAX_STR-UPDATE_DATEX sy-vline
WA_BAPI1300ADDDAX_STR-UPDATE_USER sy-vline
WA_BAPI1300ADDDAX_STR-UPDATE_USERX sy-vline
WA_BAPI1300ADDDAX_STR-SLS_MAINDEPTI sy-vline
WA_BAPI1300ADDDAX_STR-SLS_MAINDEPTIX sy-vline
WA_BAPI1300ADDDAX_STR-SLS_EXTPHYSI sy-vline
WA_BAPI1300ADDDAX_STR-SLS_EXTPHYSIX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PERMAIN sy-vline
WA_BAPI1300ADDDAX_STR-CF_PERMAINX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATMAIN sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATMAINX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PERMAINBAS sy-vline
WA_BAPI1300ADDDAX_STR-CF_PERMAINBASX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATMAINBAS sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATMAINBASX sy-vline
WA_BAPI1300ADDDAX_STR-MIN_LS sy-vline
WA_BAPI1300ADDDAX_STR-MIN_LSX sy-vline
WA_BAPI1300ADDDAX_STR-ASSIGN_FRATE sy-vline
WA_BAPI1300ADDDAX_STR-ASSIGN_FRATEX sy-vline
WA_BAPI1300ADDDAX_STR-MODULE_NO sy-vline
WA_BAPI1300ADDDAX_STR-MODULE_NOX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXT sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXT sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTA sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTAX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTA sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTAX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTB sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTBX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTB sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTBX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTC sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTCX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTC sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTCX sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTBAS sy-vline
WA_BAPI1300ADDDAX_STR-CF_PEREXTBASX sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTBAS sy-vline
WA_BAPI1300ADDDAX_STR-CF_MATEXTBASX sy-vline
WA_BAPI1300ADDDAX_STR-MLS_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-MLS_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-ULS_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-ULS_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-RULS_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-RULS_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-MLS_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-MLS_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-ULS_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-ULS_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-RULS_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-RULS_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-LLS_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-LLS_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-RLLS_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-RLLS_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-LLS_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-LLS_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-RLLS_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-RLLS_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-RETR_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-RETR_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-RETR_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-RETR_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-TDRG_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-TDRG_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-TDRG_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-TDRG_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-MINLS_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-MINLS_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-MINLS_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-MINLS_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-NORET_MAINDPT sy-vline
WA_BAPI1300ADDDAX_STR-NORET_MAINDPTX sy-vline
WA_BAPI1300ADDDAX_STR-NORET_EXTDPT sy-vline
WA_BAPI1300ADDDAX_STR-NORET_EXTDPTX sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORYX sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY_L sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY_LX sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY_R sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY_RX sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY_B sy-vline
WA_BAPI1300ADDDAX_STR-CATEGORY_BX sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.