ABAP Select data from SAP table PCONTRBALMVALL 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 PCONTRBALMVALL 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 PCONTRBALMVALL. 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 PCONTRBALMVALL 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_PCONTRBALMVALL TYPE STANDARD TABLE OF PCONTRBALMVALL, WA_PCONTRBALMVALL TYPE PCONTRBALMVALL, 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: <PCONTRBALMVALL> TYPE PCONTRBALMVALL. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PCONTRBALMVALL. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PCONTRBALMVALL INTO TABLE IT_PCONTRBALMVALL. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PCONTRBALMVALL * INTO TABLE @DATA(IT_PCONTRBALMVALL2). *--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_PCONTRBALMVALL INDEX 1 INTO DATA(WA_PCONTRBALMVALL2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PCONTRBALMVALL ASSIGNING <PCONTRBALMVALL>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PCONTRBALMVALL>-MANDT = 1.
<PCONTRBALMVALL>-COMPANYCODE = 1.
<PCONTRBALMVALL>-ACCOUNTINGPRINCIPLE = 1.
<PCONTRBALMVALL>-REVENUEACCOUNTINGCONTRACT = 1.
<PCONTRBALMVALL>-PERFORMANCEOBLIGATION = 1.
ENDLOOP. LOOP AT IT_PCONTRBALMVALL INTO WA_PCONTRBALMVALL. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PCONTRBALMVALL-REPORTINGPERIOD, sy-vline,
WA_PCONTRBALMVALL-DISCLOSURETIMEINTERVALTYPE, sy-vline,
WA_PCONTRBALMVALL-RACONTRBALISRVSDBYIMPRMTOFAST, sy-vline,
WA_PCONTRBALMVALL-SALESDOCUMENTCURRENCY, sy-vline,
WA_PCONTRBALMVALL-COMPANYCODECURRENCY, sy-vline,
WA_PCONTRBALMVALL-ADDITIONALCURRENCY1, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PCONTRBALMVALL 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_PCONTRBALMVALL 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_PCONTRBALMVALL INTO WA_PCONTRBALMVALL. *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 REVENUEACCOUNTINGCONTRACT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PCONTRBALMVALL-REVENUEACCOUNTINGCONTRACT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PCONTRBALMVALL-REVENUEACCOUNTINGCONTRACT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PERFORMANCEOBLIGATION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PCONTRBALMVALL-PERFORMANCEOBLIGATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PCONTRBALMVALL-PERFORMANCEOBLIGATION.
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_PCONTRBALMVALL_STR,
MANDT TYPE STRING,
COMPANYCODE TYPE STRING,
ACCOUNTINGPRINCIPLE TYPE STRING,
REVENUEACCOUNTINGCONTRACT TYPE STRING,
PERFORMANCEOBLIGATION TYPE STRING,
REPORTINGPERIOD TYPE STRING,
DISCLOSURETIMEINTERVALTYPE TYPE STRING,
RACONTRBALISRVSDBYIMPRMTOFAST TYPE STRING,
SALESDOCUMENTCURRENCY TYPE STRING,
COMPANYCODECURRENCY TYPE STRING,
ADDITIONALCURRENCY1 TYPE STRING,
ADDITIONALCURRENCY2 TYPE STRING,
RACONTRASTPOSTDAMTINSLSDOCCRCY TYPE STRING,
RACONTRASTPOSTDAMTINCCCRCY TYPE STRING,
RACONTRASTPOSTDAMTINADDLCRCY1 TYPE STRING,
RACONTRASTPOSTDAMTINADDLCRCY2 TYPE STRING,
CONTRLBLTYPOSTDAMTINSLSDOCCRCY TYPE STRING,
CONTRLBLTYPOSTDAMTINCOCRCY TYPE STRING,
CONTRLBLTYPOSTDAMTINADDLCRCY1 TYPE STRING,
CONTRLBLTYPOSTDAMTINADDLCRCY2 TYPE STRING,
CONTRLBLTYRPTDAMTINCOCRCY TYPE STRING,
RACONTRASSETIMPRMTINCCCRCY TYPE STRING,
RACONTRLBLTYIMPRMTINCCCRCY TYPE STRING,
RECOGNIZEDREVNAMTINCCCRCY TYPE STRING,
RACONTRASTRPTDAMTINCCCRCY TYPE STRING,
RACONTRASTRPTDAMTINSLSDOCCRCY TYPE STRING,
RACONTRASSETIMPRMTINSLSDOCCRCY TYPE STRING,
CONTRLBLTYRPTDAMTINSLSDOCCRCY TYPE STRING,
RACONTRLBLTYIMPRMTINSLSDOCCRCY TYPE STRING,
RARECOGNIZEDREVNINSLSDOCCRCY TYPE STRING,
RACONTRASTRPTDAMTINADDLCRCY1 TYPE STRING,
CONTRASSETIMPRMTAMTINADDLCRCY1 TYPE STRING,
CONTRLBLTYRPTDAMTINADDLCRCY1 TYPE STRING,
CONTRLBLTYIMPRMTAMTINADDLCRCY1 TYPE STRING,
RECOGNIZEDREVNAMTINADDLCRCY1 TYPE STRING,
RACONTRASTRPTDAMTINADDLCRCY2 TYPE STRING,
CONTRASSETIMPRMTAMTINADDLCRCY2 TYPE STRING,
CONTRLBLTYRPTDAMTINADDLCRCY2 TYPE STRING,
CONTRLBLTYIMPRMTAMTINADDLCRCY2 TYPE STRING,
RECOGNIZEDREVNAMTINADDLCRCY2 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PCONTRBALMVALL_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_PCONTRBALMVALL_STR-MANDT sy-vline
WA_PCONTRBALMVALL_STR-COMPANYCODE sy-vline
WA_PCONTRBALMVALL_STR-ACCOUNTINGPRINCIPLE sy-vline
WA_PCONTRBALMVALL_STR-REVENUEACCOUNTINGCONTRACT sy-vline
WA_PCONTRBALMVALL_STR-PERFORMANCEOBLIGATION sy-vline
WA_PCONTRBALMVALL_STR-REPORTINGPERIOD sy-vline
WA_PCONTRBALMVALL_STR-DISCLOSURETIMEINTERVALTYPE sy-vline
WA_PCONTRBALMVALL_STR-RACONTRBALISRVSDBYIMPRMTOFAST sy-vline
WA_PCONTRBALMVALL_STR-SALESDOCUMENTCURRENCY sy-vline
WA_PCONTRBALMVALL_STR-COMPANYCODECURRENCY sy-vline
WA_PCONTRBALMVALL_STR-ADDITIONALCURRENCY1 sy-vline
WA_PCONTRBALMVALL_STR-ADDITIONALCURRENCY2 sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTPOSTDAMTINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTPOSTDAMTINCCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTPOSTDAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTPOSTDAMTINADDLCRCY2 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYPOSTDAMTINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYPOSTDAMTINCOCRCY sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYPOSTDAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYPOSTDAMTINADDLCRCY2 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYRPTDAMTINCOCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASSETIMPRMTINCCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRLBLTYIMPRMTINCCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RECOGNIZEDREVNAMTINCCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTRPTDAMTINCCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTRPTDAMTINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASSETIMPRMTINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYRPTDAMTINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRLBLTYIMPRMTINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RARECOGNIZEDREVNINSLSDOCCRCY sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTRPTDAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-CONTRASSETIMPRMTAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYRPTDAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYIMPRMTAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-RECOGNIZEDREVNAMTINADDLCRCY1 sy-vline
WA_PCONTRBALMVALL_STR-RACONTRASTRPTDAMTINADDLCRCY2 sy-vline
WA_PCONTRBALMVALL_STR-CONTRASSETIMPRMTAMTINADDLCRCY2 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYRPTDAMTINADDLCRCY2 sy-vline
WA_PCONTRBALMVALL_STR-CONTRLBLTYIMPRMTAMTINADDLCRCY2 sy-vline
WA_PCONTRBALMVALL_STR-RECOGNIZEDREVNAMTINADDLCRCY2 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.