SAP Business One Universal function #STORE# capacity - sapb1

I am using SAP Business One version 9.3. I am writing a Universal Function that retrieves data from a table, places it in a #STORE variable and then calls another function to process the data. The problem I am facing is that after certain amount of characters the data in the #STORE variable gets truncated. I cannot find anywhere in the documentation what the limit for the #STORE variables is.
Here is my code:
#STORE1 = SQL(select (field1 + '*' + field2 " ':') from someTable FOR XML PATH(''));
UF(UF-002)
The idea is to create one long string from all the records in someTable, store it in #STORE1 and then use it in UF-002.
UF-002 is an Http Trigger function that calls an API with this payload:
{
"records": "#STORE1"
}
I am very new to SAP B1 and if there is a better way of doing this, I would appreciate the input. If this method is ok, what are my options for passing the data to UF-002. The table in question has about 450 records.
Thank you.

Related

BigQuery: Convert a text column to UTF-8

I want to start a Vertex AI AutoML Text Entity Extraction Batch Prediction Job, but in my own experience, texts ("content" field in the JSONL structure), must also accomplish the following two features:
Every text's size in bytes, must be between 10 and 10000 bytes: DONE
Every text encoding must be UTF-8: UNKNOWN
My original data is stored in BigQuery, so I'll have to export it to Google Cloud Storage for later batch prediction. To take advantage of BigQuery optimization, I want to accomplish the 2 previous tasks in the BigQuery data source table itself. I have checked Google's official documentation, and the closest I have got to some related information, is this; however not accurate VS what I want. BTW, the query looks as follows:
WITH mydata AS (
SELECT
CASE
WHEN BYTE_LENGTH(posting)>10000 THEN LEFT(posting, 9950)
WHEN BYTE_LENGTH(posting)<10 THEN CONCAT(posting, " is possibly an skill")
ELSE posting
END AS posting
FROM `my-project.Machine_Learning_Datasets.sample-data-source` -- Modified for data protection
)
SELECT
posting as content, -- Something needs to be done here
"text" as mimeType
FROM mydata
And my-project.Machine_Learning_Datasets.sample-data-source schema looks as follows:
Field name
Type
Mode
Records
posting
STRING
NULLABLE
100M
Any ideas?
The following answer did the job, FYI:
WITH
mydata AS (
SELECT
CASE
WHEN BYTE_LENGTH(posting)>10000 THEN LEFT(posting, 9950)
WHEN BYTE_LENGTH(posting)<10 THEN CONCAT(posting, " is possibly an skill")
ELSE
posting
END
AS posting
FROM
`my-project.Machine_Learning_Datasets.sample-data-source` )
SELECT
REGEXP_REPLACE(posting, r'[^\x00-\x7F]+', '') AS content,
"text/plain" AS mimeType
FROM
mydata
UPDATE: This case has been considered, for an improved workaround.
Thanks!

Looking for a way to get a detailed description of ZTERM

I am currently trying to program a function module which should, in theory, output a custom table like T052, but with an additional field Z_TEXTLONG, which explains the details of the chosen ZTERM, akin to the text in FI_F4_ZTERM's popup. Here's what I tried:
LOOP AT T_ZBEDS ASSIGNING FIELD-SYMBOL(<line>).
CALL FUNCTION 'FI_F4_ZTERM'
EXPORTING
I_KOART = 'K'
I_ZTERM = <line>-zterm
I_XSHOW = ''
I_ZTYPE = ''
I_NO_POPUP = 'X'
IMPORTING
E_ZTERM = v_text
EXCEPTIONS
NOTHING_FOUND = 1
OTHERS = 2.
WRITE v_text TO <line>-Z_TEXTLONG.
From what I gathered, this does not work due to FI_F4_ZTERM writing the list it returns into E_ZTERM, not a single value, which would be what I need. I am a bit lost as to what I should do next. I tried looking into how exactly FI_F4_ZTERM generates these texts or where it calls them from, but I was not successful. Currently, I am trying to maybe get this text from V_T052, but that does not work either. I would be thankful for any suggestions.
Try function FI_TEXT_ZTERM, it has single import parameter I_T052
why not just call CALL FUNCTION 'FI_F4_ZTERM'
with I_NO_POPUP = 'X'
importing
ET_ZTERM = lt_zterm.
you get the list of payment terms and their texts.
Then in the loop read it from the table of payment terms.
LOOP AT T_ZBEDS ASSIGNING FIELD-SYMBOL(<line>).
read table lt_zterm assigning <term>
with key ZTERM = <line>-zterm.
ENDLOOP.

BAPI/FM to search prod orders confirmations by workcenter and date?

I'm trying to figure out which BAPI/FM I could use to search amounts confirmed based on search criteria of date (+time if possible) and workcenter confirmed where was confirmed...
I would be using BAPI_PRODORDCONF_GETDETAIL which contains these informations, but according to BAPI guide I can only load in the data of confirmation number+confirmation counter.
Therefore the option would be to run BAPI_PRODORDCONF_GETLIST (but I can only input the production order range or confirmation number range), then filter what includes the workcenter and date I need and from those pick up confirmation number+counter and run it through BAPI_PRODORDCONF_GETDETAIL.
but this procedure of getting list of everything without data being filtered on serverside is extemly timeconsuming and out of SAP Gui I have timeout error... therefore I need any BAPI/FM which I could input the workcenter where was confirmed and date, and have the data filtered already...
Any ideas how to do that?
As far as I know there is no such standard FM, so your only choice is custom development.
I would suggest you MCPK transaction were this info is exposed in a handy form, but as I see that your requirement is to receive this info externally this is not appropriate for you.
The confirmations reside in AFRU table and workcenters are in CRHD, so to find confirmed quantities by workcenter you should join these tables, or use a view u_15673 where this info is linked:
TYPES: BEGIN OF prod_orders,
rueck TYPE afru-rueck, "confirmation number
rmzhl TYPE afru-rmzhl," confirmation counter
gmnga TYPE afru-gmnga, " quantity
arbid TYPE crhd-arbpl, " workcenter
END OF prod_orders.
DATA: orders TYPE TABLE OF prod_orders.
SELECT *
FROM u_15673
INTO CORRESPONDING FIELDS OF TABLE orders
WHERE isdd >= '20180101' AND isdz <= '163000'.
To pull this externally, you must create RFC-enabled FM or use RFC_READ_TABLE and fetch this view with parameters, here is the sample.
Another approach is to use RFC_ABAP_INSTALL_AND_RUN. You must create an ABAP program that uses WRITE for output the results as a standard list to screen.
Send the lines of this program to RFC_ABAP_INSTALL_AND_RUN to PROGRAM parameter and the code will be executed on the remote system and this FM will return screen results as the lines of table WRITES.
Possible sample based on MCPK tcode to send to RFC_ABAP_INSTALL_AND_RUN:
CLEAR lwa_selection.
lwa_selection-selname = 'SL_SPTAG'.
lwa_selection-sign = 'I'.
lwa_selection-option = 'BT'.
lwa_selection-low = '20180101'.
lwa_selection-high = '20201231'.
APPEND lwa_selection TO li_selection.
CLEAR lwa_selection.
lwa_selection-selname = 'SL_ARBPL'.
lwa_selection-sign = 'I'.
lwa_selection-option = 'EQ'.
lwa_selection-low = '10400001'.
APPEND lwa_selection TO li_selection.
SUBMIT rmcf0200 WITH SELECTION-TABLE li_selection
with par_stat = abap_true
EXPORTING LIST TO MEMORY
AND RETURN.
DATA: xlist TYPE TABLE OF abaplist.
DATA: xtext TYPE TABLE OF char200.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = xlist.
CALL FUNCTION 'LIST_TO_TXT'
EXPORTING
list_index = -1
TABLES
listtxt = xtext
listobject = xlist.
IF sy-subrc = 0.
LOOP AT xtext ASSIGNING FIELD-SYMBOL(<text>).
WRITE <xtext>.
ENDLOOP.
ENDIF.
However, this approach is not flexible because MCPK standard layout is a bit different than you want, and is not easy to adjust programmatically.
Because of that I recommend to stick to the RFC_READ_TABLE approach.

Convert a spool into text format

I want to send the spool generated by a Smart Form, by email as attachment in TXT format.
The issue is to get the spool in a TXT format, without technical stuff, just the characters in the form.
I have used the function module RSPO_RETURN_SPOOLJOB for getting it, but it returns a technical format like this:
//XHPLJIIID 0700 00000+00000+
IN01ES_CA930_DEMO_3 FIRST
OPINCH12 P 144 240 1728020160000010000100001
IN02MAIN
MT0100808400
CP11000000E
FCCOURIER 120 00144 SF001SF001110000144E
UL +0000000000000
ST0201614Dear Customer,
MT0214209000
ST0864060We would like to take this opportunity to confirm the flight
MT0100809360
ST0763253reservations listed below. Thank you for your custom.
...
I want something as follows, without the technical stuff:
Dear Customer,
We would like to take this opportunity to confirm the flight
reservations listed below. Thank you for your custom.
...
This is the code I have used :
PARAMETERS spoolnum type TSP01-RQIDENT.
DATA spool_contents type soli_tab.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spoolnum
tables
buffer = spool_contents
exceptions
others = 1.
If the parameter DESIRED_TYPE is not passed or has the value 'OTF', and the spool is of type SAPscript/Smart Form, the function module returns the technical format you have experienced.
Instead, you should use the parameter DESIRED_TYPE = 'RAW' so that all the technical stuff is interpreted and the form is returned as text, the way you request, as follows :
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spoolnum
desired_type = 'RAW'
tables
buffer = spool_contents
exceptions
others = 1.

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –
First Name (First_Name)
Last Name (Last_Name)
Year (Year)
Number (Number)
I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.
Heres is my script:
void onetime.UpdateInv()
{
for each Inventory_Record in Management
{
FN = Inventory_Record.First_Name.subString(0,1);
LN = Inventory_Record.Last_Name.subString(0,1);
YR = Inventory_Record.Year.subString(2,4);
NO = Inventory_Record.Number;
outputstr = FN + LN + YR + NO;
Inventory_Record.Inv_Num1 = outputstr;
}
}
I get this error back when I try to run this function
Error.
Error in executing UpdateInv workflow.
Error in executing For Each Record task.
Error in executing Set Variable task. Unable to update template variable FN.
Error evaluating STRING expression :
Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.
this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.
you just have put a null check on each field and u r good to go.
you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )
the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.
Since you are using substring directly in year Field, I am assuming the
year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);
so here's the formula
if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number
Let me know ur response if u implement this.
Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:
The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.
All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.